package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BankListHandler;
import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.model.request.BankListRequest;
import com.cungmua.app.model.response.BankListResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/25/14.
 */
public class BankListTask extends AuthenticatedTask<BankListRequest, Void, BankListResponse> {

    private final BankListHandler handler;
    private final Context context;

    public BankListTask(Context context, BankListHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected BankListResponse doInBackground() throws RetrofitError {
        BankListRequest request = params[0];
        return CungMuaAPI.getService().getListBank(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(BankListResponse bankListResponse) {
        handler.onListBank(bankListResponse);
    }
}

